<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">
        <h2>1. 绑定监听</h2>
        <button @click="fn1">普通函数</button>
        <button @click="fn2">箭头函数</button>
        <button @click="fn3">默认实参</button>
        <button @click="fn4(1,3,45,2,5)">多实参arguments</button>
        <button @click="fn5(3,452,5,6)">多实参展开运算符号</button>
        <button @click="fn6(12,4,523,$event)">多实参加event对象</button>
        <button @click="fn7()">不手动传参</button>
        <h2>事件修饰符</h2>
        <form>
            <button @click.prevent="fn8">阻止默认跳转</button>
        </form>
        <h2>按键修饰符</h2>
        <input type="text" v-model="inputValue" @Keydown.enter="fn9">
        <p>按下回车会提示当前输入框内容</p>
        
    </div>
    <script src="../js/vue.js"></script>
    <script>
        new Vue({
            el: '#root',
            data: {
                inputValue: ""
            },
            methods: {
                //普通函数中的this默认指向当前的Vue实例
                fn1(){
                    console.log(this);
                },
                //箭头函数中的this默认指向window对象
                fn2:() => {
                    console.log(this);
                },
                // 事件调用的函数默认会收到事件对象
                fn3(event){
                    console.log(event);
                },
                //可向原生一样用arguments接收
                fn4(){
                    console.log(arguments);
                },
                // 使用展开运算符
                fn5(...value){
                    console.log(value);
                },
                //想获得实参和event对象需要传参的时候使用vue内置的$event
                fn6(...value){
                    console.log(value);
                },
                // 不手动传参数会得到一个空数组
                fn7(...value){
                    console.log(value);
                },
                fn8(){
                    console.log('按键被按下');
                },
                fn9(){
                    alert(this.inputValue);
                }
            }
        })
    </script>
</body>
</html>